<?php

/*
	info: 网站地图
	date: 2012-4-23
*/

require dirname(__FILE__).'/include/common.inc.php';
$webglobal['file_sitemap'] = array();

//商圈信息

$webglobal['file_sitemap']['areaData'] = array();

if ($webglobal['citydata']) {
	foreach ($webglobal['citydata'] as $key => $value) {
		$value['url'] = buildURLForModule('index.php', array('city' => $value['short_english']));
		if ($childItems = $areaDataModel->getChildForLayer($key, 1, false)) {
			foreach ($childItems as $childKey => $childValue) {
				$childValue['url'] = buildURLForModule('coupon.php', array('city' => $value['short_english'], 'a' => $childKey));
				$childItems[$childKey] = $childValue;
			}
			$value['childItems'] = $childItems;
		} else {
			$value['childItems'] = array();
		}
		$webglobal['citydata'][$key] = $value;
	}
}

//优惠劵分类
if ($webglobal['couponCategory']) {
	foreach ($webglobal['couponCategory'] as $key => $value) {
		if (!isset($webglobal['couponCategory'][$value['upid']])) {
			$webglobal['couponCategory'][$key]['url'] = buildURLForModule('coupon.php', array('c' => $key));
			$webglobal['couponCategory'][$key]['childItems'] = array();
		} else {
			$value['url'] = buildURLForModule('coupon.php', array('c' => $key));
			$webglobal['couponCategory'][$value['upid']]['childItems'][$key] = $value;
			unset($webglobal['couponCategory'][$key]);
		}
	}
}

//商家分类
if ($webglobal['companyCategory']) {
	foreach ($webglobal['companyCategory'] as $key => $value) {
		$value['url'] = buildURLForModule('company.php', array('c' => $key));
		if (isset($value['second']) && $value['second']) {
			foreach ($value['second'] as $secondKey => $secondValue) {
				$secondValue['url'] = buildURLForModule('company.php', array('c' => $secondKey));
				$value['second'][$secondKey] = $secondValue;
			}
		}
		$webglobal['companyCategory'][$key] = $value;
	}
}

//新闻分类
$newsCategoryDataModel = CategoryDataModel::factory('news', array('cache' => true));
$webglobal['newsCategory'] = $newsCategoryDataModel->getChildForLayer(0, 2);

foreach ($webglobal['newsCategory'] as $key => $value) {
	if (isset($webglobal['newsCategory'][$value['upid']])) {
		$value['url'] = buildURLForModule('news.php', array('action' => 'type', 'id' => $key));
		$webglobal['newsCategory'][$value['upid']]['childItems'][$key] = $value;
		unset($webglobal['newsCategory'][$key]);
	} else {
		$webglobal['newsCategory'][$key]['url'] = buildURLForModule('news.php', array('action' => 'type', 'id' => $key));
		$webglobal['newsCategory'][$key]['childItems'] = array();
	}
}

//print_r($webglobal['newsCategory']);

template_Display('sitemap');
